home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / source / demostuf / bigrot1.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1994-07-25  |  9.4 KB  |  576 lines

  1. program rotatevild;
  2. {
  3.   VILD ROTERING #1
  4.   - af Bjarke Viksφe
  5.   feb 1994
  6.  
  7.   THIS PROGRAM WAS CODED BY BJARKE VIKS0E.
  8.   YOU ARE FREE TO DO WHATEVER YOU WANT WITH THIS PIECE OF CODE.
  9.   E-MAIL ME AT: dat92230@rix02.lyngbyes.dk IN 1994 FOR CHAT AND CODE.
  10.  
  11.   Pretty basic. Can do the stuff Future Crew did. Seems a bit jerky when
  12.   zooming at close range - maybe because of decimal lost in some
  13.   calc'ing.
  14.   Hit ESCAPE to exit...
  15. }
  16.  
  17. {$IFDEF DPMI}
  18.     Virker nu kun i real-mode pga. selvmodificerende kode!
  19.     Skift til REAL-MODE!!!!!
  20. {$ENDIF}
  21.  
  22. (*{$DEFINE DEBUG}*)
  23.  
  24. uses
  25.     DEMOINIT, ILBM256;
  26.  
  27. const
  28.     MAXY = 400;
  29.  
  30. var
  31.     i : integer;
  32.     picture        : pScreen;
  33.     tabel            : array[0..320] of integer;
  34.     xpostabel    : array[1..160] of integer;
  35.     relYtabel    : array[-MAXY..MAXY] of integer;
  36.     sinustabel  : array[0..639] of integer;
  37.     yoff            : integer;
  38.     v                : word;
  39.     vinkel1, vinkel2 : integer;
  40.     zpos            : word;
  41.     z                : longint;
  42.     inserted        : boolean;
  43.  
  44. const
  45.     display1 : word = $0000;
  46.     display2 : word = $4000;
  47.     display3 : word = $8000;
  48.  
  49.  
  50.  
  51. (*------------------------------------------------*)
  52.  
  53. procedure SwapDisplay;
  54. var
  55.     temp : word;
  56. begin
  57.     temp:=display1;
  58.     display1:=display2;
  59.     display2:=display3;
  60.     display3:=temp;
  61.     SetAddress(ptr((SEGA000),display3));
  62. end;
  63.  
  64.  
  65. (*------------------------------------------------*)
  66.  
  67. procedure SetupSinus;
  68. var
  69.     i : integer;
  70.     v, vadd : real;
  71. begin
  72.     v:=0.0;
  73.     vadd:=(2.0*pi/512.0);
  74.     for i:=0 to 639 do begin
  75.         sinustabel[i]:=round(sin(v)*32767);
  76.         v:=v+vadd;
  77.     end;
  78. end;
  79.  
  80. procedure InitDemo;
  81. var
  82.     i : integer;
  83. begin
  84.     ClearWholeScreen;
  85.     SetupSinus;
  86.  
  87.     New(picture);
  88.     LoadPix(picture, 'parasit1.lbm');
  89.     SetCMAP;
  90.  
  91.     v:=0;
  92.     zpos:=0;
  93.     for i:=-MAXY to MAXY do relYtabel[i]:=i*320;
  94. end;
  95.  
  96. procedure UninitDemo;
  97. begin
  98.     Dispose(picture);
  99. end;
  100.  
  101.  
  102. (*------------------------------------------------*)
  103.  
  104. procedure MakeXtabel; assembler;
  105. asm
  106.     mov    ax,ds
  107.     mov    es,ax
  108.     lea    di,xpostabel
  109.     lea    si,tabel+2
  110.     mov    cx,160
  111.     cld
  112. @makex1:
  113.     lodsw
  114.     mov    bx,ax
  115.     sal    bx,1
  116.     mov    ax,[OFFSET relYtabel+(MAXY*2)+bx]
  117.     stosw
  118.     add    si,2
  119.     loop    @makex1
  120.  
  121.     mov    ax,ds
  122.     mov    es,ax
  123.     lea    si,tabel
  124.     lea    di,xpostabel
  125.     mov    dx,4
  126.     mov    bx,2
  127.     mov    cx,160
  128.     cld
  129. @makex:
  130.     mov    ax,[si]
  131.     add    [di],ax
  132.     add    si,dx
  133.     add    di,bx
  134.     loop    @makex
  135. end;
  136.  
  137.  
  138. procedure CalcVinkel;
  139. begin
  140.     vinkel1:=sinustabel[v AND 511];
  141.     vinkel2:=sinustabel[(v AND 511)+128];
  142.     inc(v,1);
  143.  
  144.     z:=longdiv(sinustabel[zpos AND 511],50)+800;
  145.     inc(zpos,5);
  146. end;
  147.  
  148.  
  149. procedure RotateCoord(x,y : integer; VAR rx,ry : integer);
  150. var
  151.     cx,cy : longint;
  152. begin
  153.     cx := (longmul(x,vinkel2) - longmul(y,vinkel1)) DIV 128;
  154.     cy := (longmul(x,vinkel1) + longmul(y,vinkel2)) DIV 128;
  155.     rx := cx DIV z;
  156.     ry := cy DIV z;
  157. end;
  158.  
  159. (*------------------------------------------------*)
  160.  
  161. procedure CalcSlope(x1,y1,x2,y2, n : integer);
  162. var
  163.     x,y,delx,dely : longint;
  164. begin
  165.     delx := (x2-x1) * ($10000 DIV (n-1));
  166.     dely := (y2-y1) * ($10000 DIV (n-1));
  167.  
  168.     asm
  169.         xor    dx,dx
  170.         mov    ax,x1
  171.         mov    WORD PTR x,dx
  172.         mov    WORD PTR x+2,ax
  173.         mov    ax,y1
  174.         mov    WORD PTR y,dx
  175.         mov    WORD PTR y+2,ax
  176.  
  177.         mov    ax,ds
  178.         mov    es,ax
  179.         lea    di,tabel
  180.         mov    si,n
  181.         mov    ax,WORD PTR x+2
  182.         mov    dx,WORD PTR x
  183.         mov    bx,WORD PTR y+2
  184.         mov    cx,WORD PTR y
  185. @loop1:
  186.         add    dx,WORD PTR delx
  187.         adc    ax,WORD PTR delx+2
  188.         stosw
  189.         add    cx,WORD PTR dely
  190.         adc    bx,WORD PTR dely+2
  191.         mov    [di],bx
  192.         add    di,2
  193.         dec    si
  194.         jnz    @loop1
  195.     end;
  196. end;
  197.  
  198.  
  199. procedure BigScreenRotator(x,y : integer);
  200. var
  201.     XYoffset : integer;
  202.     screenoffset : integer;
  203. begin
  204.     screenoffset := display1+yoff;
  205.  
  206.     asm
  207.         mov    ax,y
  208.         mov    dx,320
  209.         imul    dx
  210.         add    ax,x
  211.         mov    XYoffset,ax
  212.  
  213.  
  214.         {modify code}
  215.         cmp    inserted,TRUE
  216.         je        @noinsert
  217.         mov    inserted,TRUE
  218.  
  219.         mov    bx,4
  220.         lea    si,xpostabel
  221.         lea    di,@megaloop1+2
  222.         mov    cx,40
  223. @insert1:
  224.         mov    ax,[si]
  225.         mov    [cs:di],ax
  226.         add    si,bx
  227.         add    di,bx
  228.         mov    ax,[si]
  229.         mov    [cs:di],ax
  230.         add    si,bx
  231.         add    di,5
  232.         loop    @insert1
  233.  
  234.         lea    si,xpostabel+2
  235.         lea    di,@megaloop2+2
  236.         mov    cx,40
  237. @insert2:
  238.         mov    ax,[si]
  239.         mov    [cs:di],ax
  240.         add    si,bx
  241.         add    di,bx
  242.         mov    ax,[si]
  243.         mov    [cs:di],ax
  244.         add    si,bx
  245.         add    di,5
  246.         loop    @insert2
  247. @noinsert:
  248.  
  249.  
  250.         {set bitplane}
  251.         mov    dx,$3C4
  252.         mov    ax,$0302
  253.         out    dx,ax
  254.  
  255.         push    ds
  256.         {set pixels 0,1,4,5,8,9 ... for line}
  257.         mov        es,SEGA000
  258.         mov        di,screenoffset
  259.         lds        si,picture
  260.         add        si,XYoffset
  261.         mov        bx,WIDTH
  262.         cld
  263. @megaloop1:
  264.         mov        al,[si+3000]
  265.         mov        ah,[si+3000]
  266.         stosw
  267.         mov        al,[si+3000]
  268.         mov        ah,[si+3000]
  269.         stosw
  270.         mov        al,[si+3000]
  271.         mov        ah,[si+3000]
  272.         stosw
  273.         mov        al,[si+3000]
  274.         mov        ah,[si+3000]
  275.         stosw
  276.         mov        al,[si+3000]
  277.         mov        ah,[si+3000]
  278.         stosw
  279.         mov        al,[si+3000]
  280.         mov        ah,[si+3000]
  281.         stosw
  282.         mov        al,[si+3000]
  283.         mov        ah,[si+3000]
  284.         stosw
  285.         mov        al,[si+3000]
  286.         mov        ah,[si+3000]
  287.         stosw
  288.         mov        al,[si+3000]
  289.         mov        ah,[si+3000]
  290.         stosw
  291.         mov        al,[si+3000]
  292.         mov        ah,[si+3000]
  293.         stosw
  294.         mov        al,[si+3000]
  295.         mov        ah,[si+3000]
  296.         stosw
  297.         mov        al,[si+3000]
  298.         mov        ah,[si+3000]
  299.         stosw
  300.         mov        al,[si+3000]
  301.         mov        ah,[si+3000]
  302.         stosw
  303.         mov        al,[si+3000]
  304.         mov        ah,[si+3000]
  305.         stosw
  306.         mov        al,[si+3000]
  307.         mov        ah,[si+3000]
  308.         stosw
  309.         mov        al,[si+3000]
  310.         mov        ah,[si+3000]
  311.         stosw
  312.         mov        al,[si+3000]
  313.         mov        ah,[si+3000]
  314.         stosw
  315.         mov        al,[si+3000]
  316.         mov        ah,[si+3000]
  317.         stosw
  318.         mov        al,[si+3000]
  319.         mov        ah,[si+3000]
  320.         stosw
  321.         mov        al,[si+3000]
  322.         mov        ah,[si+3000]
  323.         stosw
  324.         mov        al,[si+3000]
  325.         mov        ah,[si+3000]
  326.         stosw
  327.         mov        al,[si+3000]
  328.         mov        ah,[si+3000]
  329.         stosw
  330.         mov        al,[si+3000]
  331.         mov        ah,[si+3000]
  332.         stosw
  333.         mov        al,[si+3000]
  334.         mov        ah,[si+3000]
  335.         stosw
  336.         mov        al,[si+3000]
  337.         mov        ah,[si+3000]
  338.         stosw
  339.         mov        al,[si+3000]
  340.         mov        ah,[si+3000]
  341.         stosw
  342.         mov        al,[si+3000]
  343.         mov        ah,[si+3000]
  344.         stosw
  345.         mov        al,[si+3000]
  346.         mov        ah,[si+3000]
  347.         stosw
  348.         mov        al,[si+3000]
  349.         mov        ah,[si+3000]
  350.         stosw
  351.         mov        al,[si+3000]
  352.         mov        ah,[si+3000]
  353.         stosw
  354.         mov        al,[si+3000]
  355.         mov        ah,[si+3000]
  356.         stosw
  357.         mov        al,[si+3000]
  358.         mov        ah,[si+3000]
  359.         stosw
  360.         mov        al,[si+3000]
  361.         mov        ah,[si+3000]
  362.         stosw
  363.         mov        al,[si+3000]
  364.         mov        ah,[si+3000]
  365.         stosw
  366.         mov        al,[si+3000]
  367.         mov        ah,[si+3000]
  368.         stosw
  369.         mov        al,[si+3000]
  370.         mov        ah,[si+3000]
  371.         stosw
  372.         mov        al,[si+3000]
  373.         mov        ah,[si+3000]
  374.         stosw
  375.         mov        al,[si+3000]
  376.         mov        ah,[si+3000]
  377.         stosw
  378.         mov        al,[si+3000]
  379.         mov        ah,[si+3000]
  380.         stosw
  381.         mov        al,[si+3000]
  382.         mov        ah,[si+3000]
  383.         stosw
  384.  
  385.         {set bitplane}
  386.         mov    dx,$3C4
  387.         mov    ax,$0C02
  388.         out    dx,ax
  389.         {set pixels 2,3,6,7,10,11 ... for line}
  390.         mov        di,screenoffset
  391. @megaloop2:
  392.         mov        al,[si+3000]
  393.         mov        ah,[si+3000]
  394.         stosw
  395.         mov        al,[si+3000]
  396.         mov        ah,[si+3000]
  397.         stosw
  398.         mov        al,[si+3000]
  399.         mov        ah,[si+3000]
  400.         stosw
  401.         mov        al,[si+3000]
  402.         mov        ah,[si+3000]
  403.         stosw
  404.         mov        al,[si+3000]
  405.         mov        ah,[si+3000]
  406.         stosw
  407.         mov        al,[si+3000]
  408.         mov        ah,[si+3000]
  409.         stosw
  410.         mov        al,[si+3000]
  411.         mov        ah,[si+3000]
  412.         stosw
  413.         mov        al,[si+3000]
  414.         mov        ah,[si+3000]
  415.         stosw
  416.         mov        al,[si+3000]
  417.         mov        ah,[si+3000]
  418.         stosw
  419.         mov        al,[si+3000]
  420.         mov        ah,[si+3000]
  421.         stosw
  422.         mov        al,[si+3000]
  423.         mov        ah,[si+3000]
  424.         stosw
  425.         mov        al,[si+3000]
  426.         mov        ah,[si+3000]
  427.         stosw
  428.         mov        al,[si+3000]
  429.         mov        ah,[si+3000]
  430.         stosw
  431.         mov        al,[si+3000]
  432.         mov        ah,[si+3000]
  433.         stosw
  434.         mov        al,[si+3000]
  435.         mov        ah,[si+3000]
  436.         stosw
  437.         mov        al,[si+3000]
  438.         mov        ah,[si+3000]
  439.         stosw
  440.         mov        al,[si+3000]
  441.         mov        ah,[si+3000]
  442.         stosw
  443.         mov        al,[si+3000]
  444.         mov        ah,[si+3000]
  445.         stosw
  446.         mov        al,[si+3000]
  447.         mov        ah,[si+3000]
  448.         stosw
  449.         mov        al,[si+3000]
  450.         mov        ah,[si+3000]
  451.         stosw
  452.         mov        al,[si+3000]
  453.         mov        ah,[si+3000]
  454.         stosw
  455.         mov        al,[si+3000]
  456.         mov        ah,[si+3000]
  457.         stosw
  458.         mov        al,[si+3000]
  459.         mov        ah,[si+3000]
  460.         stosw
  461.         mov        al,[si+3000]
  462.         mov        ah,[si+3000]
  463.         stosw
  464.         mov        al,[si+3000]
  465.         mov        ah,[si+3000]
  466.         stosw
  467.         mov        al,[si+3000]
  468.         mov        ah,[si+3000]
  469.         stosw
  470.         mov        al,[si+3000]
  471.         mov        ah,[si+3000]
  472.         stosw
  473.         mov        al,[si+3000]
  474.         mov        ah,[si+3000]
  475.         stosw
  476.         mov        al,[si+3000]
  477.         mov        ah,[si+3000]
  478.         stosw
  479.         mov        al,[si+3000]
  480.         mov        ah,[si+3000]
  481.         stosw
  482.         mov        al,[si+3000]
  483.         mov        ah,[si+3000]
  484.         stosw
  485.         mov        al,[si+3000]
  486.         mov        ah,[si+3000]
  487.         stosw
  488.         mov        al,[si+3000]
  489.         mov        ah,[si+3000]
  490.         stosw
  491.         mov        al,[si+3000]
  492.         mov        ah,[si+3000]
  493.         stosw
  494.         mov        al,[si+3000]
  495.         mov        ah,[si+3000]
  496.         stosw
  497.         mov        al,[si+3000]
  498.         mov        ah,[si+3000]
  499.         stosw
  500.         mov        al,[si+3000]
  501.         mov        ah,[si+3000]
  502.         stosw
  503.         mov        al,[si+3000]
  504.         mov        ah,[si+3000]
  505.         stosw
  506.         mov        al,[si+3000]
  507.         mov        ah,[si+3000]
  508.         stosw
  509.         mov        al,[si+3000]
  510.         mov        ah,[si+3000]
  511.         stosw
  512.  
  513.         pop        ds
  514.     end;
  515. end;
  516.  
  517.  
  518. procedure RotateScreen;
  519. var
  520.     x, y    : integer;
  521.     i        : integer;
  522. begin
  523.     yoff:=0;
  524.     inserted:=FALSE;
  525.     i:=0;
  526.     while (i<200) do begin
  527.         x:=tabel[i]; y:=tabel[i+1];
  528.         BigScreenRotator(x,y);
  529.         inc(i,2);
  530.         inc(yoff,WIDTH);
  531.     end;
  532. end;
  533.  
  534.  
  535. (*------------------------------------------------*)
  536.  
  537. procedure RunOnce;
  538. var
  539.     x1,y1, x2,y2 : integer;
  540. begin
  541.     SwapDisplay;
  542.     while retraces=0 do ;
  543.     retraces:=0;
  544. {$IFDEF DEBUG}
  545.     setRGB(0,63,0,0);
  546. {$ENDIF}
  547.     CalcVinkel;
  548.  
  549.     RotateCoord(-200,0,x1,y1);
  550.     RotateCoord(200,0,x2,y2);
  551.     CalcSlope(x1,y1,x2,y2,160);
  552.     MakeXtabel;
  553.  
  554.     RotateCoord(0,-180,x1,y1);
  555.     RotateCoord(0,180,x2,y2);
  556.     inc(x1,160); inc(x2,160);
  557.     inc(y1,100); inc(y2,100);
  558.     CalcSlope(x1,y1,x2,y2,100);
  559.     RotateScreen;
  560. {$IFDEF DEBUG}
  561.     setRGB(0,0,0,0);
  562. {$ENDIF}
  563. end;
  564.  
  565.  
  566. begin
  567.     OpenScreen;
  568.     SetLineRepeat(3);
  569.     InitDemo;
  570.     SetAllInterrupts;
  571.     while not (Key='e') do RunOnce;
  572.     RestoreAllInterrupts;
  573.     CloseScreen;
  574.     UninitDemo;
  575. end.
  576.